function [failbit, ndata]=f5_setValue(data, value, k, n)
    if nargin ~= 4
        error 'number of arguments should be 4: [failbit, ndata] = f5_setValue(data, value, k, n)'
    end
    cvalue = f5_getValueAsF4(data, k, n);
    %cvalue = f5_getValueAsF3(data, k, n);
    v = uint16(0);
    for i = 1:k
        if mod(value(1, i), 2) ~= mod(cvalue(1,i),2)
            v = bitset(v, i);
        end
    end
    % only modify one bit: -1 for succeed, other for fail
    failbit = -1;
    ndata = data;
    if v > 0
        u = ndata(1,v);
        if u == 0
            error('u must not be 0')
        end
        if u > 0
            ndata(1, v) = u - 1;
        else
            ndata(1, v) = u + 1;
        end
        if ndata(1, v) == 0
            failbit = v;
        end
    end
end
